package com.example.demo01.service;

import com.example.demo01.mapper.FormInfoMapper;
import com.example.demo01.mapper.UserMapper;
import com.example.demo01.pojo.FormInfo;
import com.example.demo01.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Optional;

@Service
public class UserService {
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private FormInfoMapper formInfoMapper;

    public boolean checkActive(String username){
        User user=userMapper.getUserByName(username);
        if(user.getActive().equals("是")){
            return true;

        }else{
            return false;
        }
    }

    public boolean isValidUser(String username, String password){
        User user=userMapper.getUserByName(username);
        if(password.equals(user.getPassword())){
            return true;
        }else{
            return false;
        }
    }


    public String getRoleByName(String username){
        User user=userMapper.getUserByName(username);
        return user.getRole();
    }

   public void updatePostTimeByName(String username){

        userMapper.updatePostTimeByName(username);
   }

    @Transactional
   public void updateActiveWithFalse(String username){

        userMapper.updateActiveWithFalse(username);

   }

   @Transactional
   public void updateActiveWithTrue(String username){

        userMapper.updateActiveWithTrue(username);
   }


   public void addUser(User user){

        userMapper.addUser(user);
   }

   public User getUserByName(String username){
        return userMapper.getUserByName(username);
   }


}
